//
//  MessageToolbar.m
//  CarTown
//
//  Created by xionghao on 15/8/15.
//  Copyright (c) 2015年 熊浩. All rights reserved.
//

#import "MessageToolbar.h"

@interface MessageToolbar()<UITextViewDelegate>
@property (weak, nonatomic)  UIButton *sendbtn;

@property (weak, nonatomic)  UIView *messagebg;

@end

@implementation MessageToolbar

-(instancetype)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        UIButton *imgpicker=[[UIButton alloc]initWithFrame:CGRectMake(16, 10, 26, 23)];
        [imgpicker setImage:[UIImage imageNamed:@"照相机"] forState:UIControlStateNormal];
        [imgpicker addTarget:self action:@selector(takepicclick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:imgpicker];
        
        UIButton *sendbtn=[[UIButton alloc]initWithFrame:CGRectMake(XHScreenwidth-46-16, 7, 46, 30)];
        [sendbtn setTitle:@"发送" forState:UIControlStateNormal];
        [sendbtn setTitleColor:tintblue forState:UIControlStateNormal];
        [sendbtn setTitleColor:placehodlerColor forState:UIControlStateDisabled];
        [sendbtn addTarget:self action:@selector(send:) forControlEvents:UIControlEventTouchUpInside];
        sendbtn.enabled=NO;
        [self addSubview:sendbtn];
        self.sendbtn=sendbtn;
        UITextView *messagetext=[[UITextView alloc] initWithFrame:CGRectMake(58, 8, XHScreenwidth-46-58-16-8, 33)];
        messagetext.delegate=self;
        [self addSubview:messagetext];
        self.messagetext=messagetext;
        self.messagetext.layer.cornerRadius=5;
        self.messagetext.layer.borderWidth=1;
        self.messagetext.layer.borderColor=[UIColorWithRGB(238, 238, 238) CGColor];
        self.backgroundColor=RGBACOLOR(242, 242, 242, 0.8);
        
    }
    return self;
}

+(instancetype)toolbar{
    MessageToolbar *toolbar=[[MessageToolbar alloc]initWithFrame:CGRectMake(0, XHScreenheight-44, XHScreenwidth, 44)];
    return toolbar;
}

-(void)awakeFromNib{
  
}
-(void)textViewDidChange:(UITextView *)textView{
    if (textView.text.length>0) {
        self.sendbtn.enabled=YES;
    }else{
        self.sendbtn.enabled=NO;
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (IBAction)takepicclick:(id)sender {
    if ([_delegate respondsToSelector:@selector(clickWithTag:)]) {
        [_delegate clickWithTag:0];
    }
}
- (IBAction)send:(id)sender {
    
    if ([_delegate respondsToSelector:@selector(clickWithTag:)]) {
        [_delegate clickWithTag:1];
    }
}

@end
